#include "Plugin.h"
#include "dom\nsIDOMDocument.h"
#include "dom\nsIDOMLocation.h"
#include <string>

#include "dom\nsPIDOMWindow.h"
#include "widget\nsIBaseWindow.h"

#include "appshell\nsIXULWindow.h"
#include "appshell\nsIXULBrowserWindow.h"
#include "dom\nsIDOMJSWindow.h"

#include "dom\nsIDOMChromeWindow.h"

#include "dom\nsIBrowserDOMWindow.h"

#ifdef _DEBUG
	#import "..\\..\\..\\..\\Target\\Debug\\FirefoxResolver.tlb" 
#else
	#import "..\\..\\..\\..\\Target\\Release\\FirefoxResolver.tlb"
#endif
using namespace FirefoxResolver;

NS_IMPL_ISUPPORTS1(OoganizerPlugin, IOoganizerPlugin)

OoganizerPlugin::OoganizerPlugin()
{
	CoInitialize(NULL);

	/* member initializers and constructor code */
	mName.Assign(L"OoganizerPlugin");	

	// Initialize My Added Members
	nsresult rv = NS_GetServiceManager(getter_AddRefs(m_servMan)); 

	if (NS_FAILED(rv)) 
		throw -1; 

	rv = m_servMan->GetServiceByContractID("@mozilla.org/appshell/window-mediator;1", 
		NS_GET_IID(nsIWindowMediator), 
		getter_AddRefs(m_windowMediator)); 

	if (NS_FAILED(rv)) 
		throw -1; 
}

OoganizerPlugin::~OoganizerPlugin()
{
	/* destructor code */
	CoUninitialize();
}

/* long add (in long a, in long b); */
NS_IMETHODIMP OoganizerPlugin::Add(PRInt32 a, PRInt32 b, PRInt32 *_retval)
{	
	*_retval = a + b;
	
	_bstr_t doris("Daniel is here");
	_bstr_t doris2("Daniel is still here");
	IFirefoxPluginCallsIntoHerePtr pIFirefoxResolver(__uuidof(FoxResolver));

	// This should work!!!!
	pIFirefoxResolver->PluginEntersURLsAndTitles(doris, doris2);

	return NS_OK;
}

/* attribute AString name; */
NS_IMETHODIMP OoganizerPlugin::GetName(nsAString & aName)
{
	aName.Assign(mName);
	return NS_OK;
}

NS_IMETHODIMP OoganizerPlugin::SetName(const nsAString & aName)
{
	mName.Assign(aName);
	return NS_OK;
}
